package org.itboys.core.controller.front;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.itboys.commons.CommonConstants;
import org.itboys.core.entity.mongo.SundayTimeConfig;
import org.itboys.core.service.mongo.front.SundayFrontTimeConfigService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/16
 * Description: 小程序端
 */

@Controller
@RequestMapping("/sunday/small/timeConfig")
@Api(value = "timeConfig",description = "配送时间段")
public class SundayFrontTimeConfigController extends BaseController {
    @Autowired
    private SundayFrontTimeConfigService timeConfigService;

    @RequestMapping(value="/select", method= {RequestMethod.POST})
    @ApiOperation(value="小程序 获取时间段")
    public void select(
            HttpServletRequest request,
            HttpServletResponse response
    ){
        try{
            List<SundayTimeConfig> result =timeConfigService.select();
            ResponseMessage.success(result);
        }catch (Exception e){
            String msg = CommonConstants.ERROMSG;
            Integer code=CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/sunday/small/timeConfig/select----e="+e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(code,msg);
        }
    }

}
